package com.maxd.modules.selfshop.merchants.respository;


import com.maxd.modules.selfshop.merchants.entity.SelfMargin;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface SelfMarginJpaRepository extends JpaRepository<SelfMargin, Long> {

    //分页查询
    Page<SelfMargin> findAll(Pageable pageable);

    //条件查询
    Page<SelfMargin> findAll(Specification<SelfMargin> specification, Pageable pageable);

    //根据订单id查询
    SelfMargin findByOrderId(Long orderId);

    //退款发起
    @Modifying
    @Transactional
    @Query(value = "update SelfMargin s set s.refundStartTime=:refundStartTime where s.orderId=:orderId")
    Integer refundStartMargin(@Param("orderId") Long orderId, @Param("refundStartTime") String refundStartTime);

}
